package com.hhkj.admin.course.domain;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.cont.SysConst;
import com.ruoyi.common.core.domain.BizBaseEntity;
import com.ruoyi.common.valid.VAdd;
import com.ruoyi.common.valid.VDisable;
import com.ruoyi.common.valid.VEdit;
import com.ruoyi.common.valid.emun.EnumValueCheck;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 课程信息对象 t_course
 *
 * @author ruoyi
 * @since 2023-05-09
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("t_course")
@NoArgsConstructor
@AllArgsConstructor
public class Course extends BizBaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 课程名称 */
    @Excel(name = "课程名称")
    @NotBlank(message = "课程名称不能为空", groups = {VAdd.class, VEdit.class})
    private String name;

    /** 层级序号 1类型 2类别 3科目 */
    @TableField(updateStrategy = FieldStrategy.NEVER)
    @Excel(name = "层级序号 1类型 2类别 3科目")
    private Integer levelNum;

    /** 顺序序号 */
    private Integer orderNum;

    /** 父类id，关联本表主键，一级父id为0 */
    @Excel(name = "父类id，关联本表主键，一级父id为0")
    @TableField(updateStrategy = FieldStrategy.NEVER)
    @NotNull(message = "上级课程不能为空", groups = {VAdd.class})
    private Long parentId;

    /** 上级名称 */
    @TableField(exist = false)
    private String parentName;

    /** 上上级id */
    @TableField(exist = false)
    private Long rootId;

    /** 上上级名称 */
    @TableField(exist = false)
    private String rootName;

    /** 禁用标签 0-否 1-是 默认0 */
    @Excel(name = "禁用标签 0-否 1-是 默认0")
    @NotNull(message = "禁用标签不能为空", groups = {VDisable.class})
    @EnumValueCheck(message = "禁用标签值错误: 0-否 1-是", groups = {VDisable.class}, target = SysConst.Flag.class)
    private Integer disableFlag;

    /** 子课程列表 */
    @TableField(exist = false)
    private List<Course> children;

    /** 类型列表 */
    @TableField(exist = false)
    private List<CourseBankType> bankTypeList;

    /** 课程价格列表 **/
    @TableField(exist = false)
    private List<CoursePriceConf> coursePriceConfList;

    /** 结构化名称 */
    @TableField(exist = false)
    private String structureName;

    /** id主键list */
    @TableField(exist = false)
    private List<Long> idList;

    /**
     * 是否隐藏 1-是 0-否
     */
    private Integer needHiddenFlag;

    /** 今日题库新增数量 */
    @JsonIgnore
    @TableField(exist = false)
    private Integer todayBankAmount;

    public Course(Long id, Long parentId, Integer disableFlag)
    {
        this.setId(id);
        this.parentId = parentId;
        this.disableFlag = disableFlag;
    }

    @Override
    @NotNull(message = "唯一主键不能为空", groups = {VEdit.class, VDisable.class})
    public Long getId()
    {
        return super.getId();
    }

    public Integer getDisableFlag()
    {
        return disableFlag == null ? SysConst.Flag.NO.getFlag() : disableFlag;
    }
}
